from config import *
from utils import *

question_templates = [
    "Please mark a pixel point on the desktop that lies between {object_a} and {object_b}, and is located {direction}.",
    "Identify a pixel on the desktop situated between {object_a} and {object_b}, positioned {direction}.",
    "Locate a pixel point on the desktop that is between {object_a} and {object_b}, and lies {direction}.",
    "Find a pixel on the desktop that is between {object_a} and {object_b}, and is located {direction}.",
    "Please specify a pixel location on the desktop that lies between {object_a} and {object_b}, and is situated {direction}.",
    "Determine a pixel point on the desktop that is between {object_a} and {object_b}, and located {direction}.",
    "Provide the coordinates of a pixel on the desktop that lies between {object_a} and {object_b}, and is positioned {direction}.",
    "Identify a pixel on the desktop that is between {object_a} and {object_b}, and lies {direction}.",
    "Please locate a pixel point on the desktop that is between {object_a} and {object_b}, and situated {direction}.",
    "Find a pixel on the desktop that lies between {object_a} and {object_b}, and is located {direction}.",
    "Specify a pixel location on the desktop that is between {object_a} and {object_b}, and lies {direction}.",
    "Determine a pixel on the desktop that is between {object_a} and {object_b}, and is situated {direction}.",
    "Please identify a pixel point on the desktop that lies between {object_a} and {object_b}, and is located {direction}.",
    "Locate a pixel on the desktop that is between {object_a} and {object_b}, and positioned {direction}.",
    "Find a pixel point on the desktop that lies between {object_a} and {object_b}, and is situated {direction}.",
    "Provide a pixel location on the desktop that is between {object_a} and {object_b}, and lies {direction}.",
    "Identify a pixel on the desktop that lies between {object_a} and {object_b}, and is located {direction}.",
    "Please specify a pixel point on the desktop that is between {object_a} and {object_b}, and situated {direction}.",
    "Determine a pixel location on the desktop that lies between {object_a} and {object_b}, and is positioned {direction}.",
    "Locate a pixel on the desktop that is between {object_a} and {object_b}, and lies {direction}."
]

def gen_extra2_qa(obj_dict, cam, table):
    qa = []
    anchor = []
    for id, info in obj_dict.items():
        if '_' in id:
            continue
        if not info['visible']:
            return []
        anchor.append(info)
    if len(anchor) != 2:
        return []
    for id, info in obj_dict.items():
        if '_' not in id:
            continue
        if not info['visible']:
            continue
        if info['direction'][2] == 1:
            continue
        ref1 = choice(anchor[0]['exclusive_ref'])
        ref2 = choice(anchor[1]['exclusive_ref'])
        ref3 = choice(info['exclusive_ref'])
        desc1 = ref_to_desc(ref1)
        desc2 = ref_to_desc(ref2)
        desc3 = ref_to_desc(ref3)
        question = choice(question_templates).format(object_a = desc1, object_b = desc2, direction = info['dir_desc'].replace('OBJECT', desc3))
        if random() < 0.4:
            question = question + SUFFIX
        answer_loc = info['answer']
        pix = world_to_camera_pixel((answer_loc[0], answer_loc[1], table[4]), cam)
        answer = f'[{format_coordinatexy(pix[0], pix[1])}]'
        thinking = f'''
{ref_to_thinking(obj_dict, anchor[0], ref1, desc1)}
{ref_to_thinking(obj_dict, anchor[1], ref2, desc2)}
{ref_to_thinking(obj_dict, info, ref3, desc3)}
So one of the coordinate positions that satisfies the conditions is {format_coordinatexy(pix[0], pix[1])}.
        '''
        qa.append({
            'question': question,
            'answer': answer,
            'thinking': thinking,
        })
    return qa